package grpc

import (
	"context"
	"strings"

	"gitee.com/xgotool/sqlite-logs-more/protoc"
	"gitee.com/xgotool/sqlite-logs-more/service/rootdb"
	"github.com/golang/protobuf/ptypes/empty"
	"google.golang.org/protobuf/types/known/emptypb"
)

// 设置设备信息
func (c *GrpcRemote) Set(cnt context.Context, inf *protoc.ClientRemoteSet) (*empty.Empty, error) {
	// 设置设备详情
	der, err := getDid(cnt)
	if err != nil {
		return nil, notFond(err)
	}
	if c.Dervice == nil {
		c.Dervice = der
	}
	der.Name = inf.Name
	der.Desc = inf.Desc
	der.Ip = inf.Ip
	der.Goos = inf.Goos
	der.Names = strings.Join(inf.Names, ",")
	err = rootdb.DerviceSet(der)
	if err != nil {
		return nil, sysErr(err)
	}
	return &emptypb.Empty{}, nil
}
